<template>
  <div class="info">
    <h3>基本信息</h3>
    <el-divider />
    <div class="infoForm"></div>
    <el-form :model="form" label-width="0px" :rules="rules" v-loading="loading">
      <h5>
        仓库名称<el-icon color="red" size="12px"><Star /></el-icon>
      </h5>
      <el-form-item prop="name" size="large">
        <el-input disabled v-model="form.name" />
      </el-form-item>

      <h5>语言</h5>
      <el-form-item>
        <el-select
          v-model="form.language"
          placeholder="请选择语言"
          style="width: 600px"
          size="large"
        >
          <el-option label="java" value="java" />
          <el-option label="cpp" value="cpp" />
          <el-option label="javascript" value="javascript" />
          <el-option label="c" value="c" />
        </el-select>
      </el-form-item>

      <h5>仓库状态</h5>
      <el-form-item>
        <el-radio-group v-model="form.state" size="large">
          <el-radio :label="0">开源</el-radio>
          <el-radio :label="1">私有</el-radio>
        </el-radio-group>
      </el-form-item>

      <h5>介绍</h5>
      <el-form-item>
        <el-input v-model="form.introduction" type="textarea" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="submit">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { ElMessage } from "element-plus";
import request from "@/utils/request";
export default {
  data() {
    return {
      loading: true,
      form: {
        name: this.$route.params.housename,
        language: "",
        state: 1,
        introduction: "",
      },
      rules: {
        name: [{ required: true, message: "请输入仓库名称", trigger: "blur" }],
      },
    };
  },
  mounted() {
    request
      .post(
        `/house/basicinfo?ownername=${this.$route.params.username}&housename=${this.$route.params.housename}`
      )
      .then((res) => {
        if (res.code == 200) {
          this.form.language = res.data.houselang;
          this.form.state = res.data.housetype;
          this.form.introduction = res.data.houseintro;
        }
      });
    this.loading = false;
  },
  methods: {
    submit() {
      request
        .post(
          `/house/basicinfomanage?ownername=${this.$route.params.username}&housename=${this.$route.params.housename}&language=${this.form.language}&state=${this.form.state}&type=${this.form.state}&intro=${this.form.introduction}`
        )
        .then((res) => {
          if (res.code == 200) {
            ElMessage("成功");
          } else {
            ElMessage("失败");
          }
        });
    },
  },
};
</script>

<style>
.info {
  display: inline-block;
  position: absolute;
  margin-top: 3%;
  margin-left: 5%;
}
.infoForm {
  margin-top: 3%;
  margin-left: 3%;
}
</style>
